﻿<UserControl x:Class="BingMapBrowser.MainPage"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:map="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
	xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
	xmlns:local="clr-namespace:BingMapBrowser"
	mc:Ignorable="d"
	d:DesignHeight="400" d:DesignWidth="800">
	<UserControl.Resources>
		<DataTemplate x:Key="EntityTemplate">
			<map:Pushpin Name="EntityPushPin" map:MapLayer.Position="{Binding Address.Location}" MouseLeftButtonDown="EntityPushPin_MouseLeftButtonDown" Background="{Binding ToolTip.Color}">
				<ToolTipService.ToolTip>
					<StackPanel>
						<TextBlock Text="{Binding EntityDisplayName}" Padding="2" FontWeight="Bold" TextWrapping="Wrap"/>
						<StackPanel Margin="2" Orientation="Horizontal">
							<TextBlock Text="{Binding ToolTip.Text}" Padding="2" FontWeight="Bold" TextWrapping="Wrap"></TextBlock>
							<TextBlock Text="{Binding ToolTip.Value}" Padding="2" TextWrapping="Wrap"></TextBlock>
						</StackPanel>
						<TextBlock Text="Click Pushpin for details" Foreground="Gray" Padding="2" Margin="2" TextWrapping="Wrap"/>
					</StackPanel>
				</ToolTipService.ToolTip>
			</map:Pushpin>
		</DataTemplate>
	</UserControl.Resources>

	<Grid x:Name="LayoutRoot" Background="White">
		<Grid.RowDefinitions>
			<RowDefinition Height="30"></RowDefinition>
			<RowDefinition Height="30"></RowDefinition>
			<RowDefinition Height="2.5*"></RowDefinition>
			<RowDefinition Height="30"></RowDefinition>
			<RowDefinition Height="1.5*"></RowDefinition>
		</Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="2*"></ColumnDefinition>
			<ColumnDefinition Width="1*"></ColumnDefinition>
		</Grid.ColumnDefinitions>
		<Grid Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2">
            <Border Background="#a7cdf0" BorderThickness="1" BorderBrush="White" CornerRadius="10" Margin="3">
			<StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2">
					<StackPanel Orientation="Horizontal">
						<ComboBox Name="EntityPicker" Width="100" SelectionChanged="EntityPicker_SelectionChanged" Margin="10,0,0,0"></ComboBox>
						<Button Name="LoadRecords" Content="Load" Width="80" Margin="10,0,0,0" Click="LoadRecords_Click"></Button>
					</StackPanel>
			</StackPanel>
			</Border>
		</Grid>
		<Grid Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2">
            <Border Background="#a7cdf0" BorderThickness="1" BorderBrush="White" CornerRadius="10" Margin="3">
				<Grid Name="filters"></Grid>
			</Border>
		</Grid>
		<Grid Grid.Row="2" Grid.RowSpan="3" Grid.Column="0" Grid.ColumnSpan="2">
		<Border Background="Gray" BorderBrush="White" BorderThickness="1" CornerRadius="10" Margin="3">
			<map:Map x:Name="bingMap" 
					 Mode="Road" MouseClick="bingMap_MouseClick">
				<map:MapItemsControl x:Name="entityList"
							ItemTemplate="{StaticResource EntityTemplate}"
							ItemsSource="{Binding AllRecords}">
				</map:MapItemsControl>
			</map:Map>
		</Border>
		</Grid>
		<Grid Grid.Column="1" Grid.Row="2">
            <Border Visibility="Collapsed" Name="detailsPane" BorderThickness="1" BorderBrush="White" Background="#a7cdf0" CornerRadius="10" Margin="3">
                <Border BorderThickness="1" BorderBrush="#a7cdf0" CornerRadius="10" Margin="1">
					<StackPanel>
                        <StackPanel Orientation="Horizontal" Background="#a7cdf0" Height="24">
							<Button Content="X" Name="CloseButton" Click="CloseButton_Click" HorizontalAlignment="Right" Width="20" Margin="2"/>
							<TextBlock Text=" Details" Padding="5" Foreground="White"/>
						</StackPanel>
						<local:RecordView Margin="5" x:Name="fullRecordView"/>
					</StackPanel>
				</Border>
			</Border>
		</Grid>
		<Grid Grid.Row="3" Grid.Column="1">
			<Border BorderThickness="1" CornerRadius="10" Margin="3">
				<StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Left">
					<TextBlock Text="LatLong: " Name="latLongLabel"></TextBlock>
					<TextBlock Text="Distance(KMs): "></TextBlock>
					<TextBox Name="distance" Text="0.0" MinWidth="50"></TextBox>
					<Button Name="loadNearRecordsButton" Content="Load" Click="loadNearRecordsButton_Click" Width="80"></Button>
				</StackPanel>
			</Border>
		</Grid>
		<Grid Grid.Row="4" Grid.Column="1">
			<Border BorderThickness="1" CornerRadius="10" Margin="3">
				<StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2">
					<data:DataGrid Name="nearRecordsGrid" ItemsSource="{Binding NearRecords}" AutoGenerateColumns="False" MouseRightButtonDown="nearRecordsGrid_MouseRightButtonDown">
						<data:DataGrid.Columns>
							<data:DataGridTextColumn Binding="{Binding EntityDisplayName}"></data:DataGridTextColumn>
							<data:DataGridTextColumn Binding="{Binding ListItems[0].Value}"></data:DataGridTextColumn>
							<data:DataGridTextColumn Binding="{Binding ListItems[1].Value}"></data:DataGridTextColumn>
							<data:DataGridTextColumn Binding="{Binding ListItems[2].Value}"></data:DataGridTextColumn>
						</data:DataGrid.Columns>
					</data:DataGrid>
				</StackPanel>
			</Border>
		</Grid>
	</Grid>
</UserControl>
